package com.ftg.learn.day12;

import java.util.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * 队列 ... fifo
 * @author 布衣
 */
public class JoseCircle {

    public static int jose(int nums, int k) {
        Queue<Integer> q = new ArrayDeque<>();
        for (int i = 0; i < nums; i++) {
            q.offer(i+1);
        }
        while(q.size() > 1){
            for (int i = 0; i < k - 1; i++) {
                q.add(q.poll());
            }
            q.poll();
        }
        return q.peek();
    }

    public static void main(String[] args) {
        //8
//        17
        System.out.println(JoseCircle.jose(16, 3));
        Deque<String> d1 = new LinkedList<>();
        d1.add("aaa");
        d1.addLast("bbbb");
        d1.addFirst("王思陪聪");
        System.out.println(d1);


        BlockingQueue<String> as = new LinkedBlockingQueue<>();
        as.add("aaa");
        as.add("bbb");
        as.add("ccc");
        as.add("ddd");
        System.out.println(as);
    }

}
